# Copyright (c) 2023 Jane Doe
# MIT License (see LICENSE or https://opensource.org/licenses/MIT)


import random

def comparison(player_num, system_num):
    if player_num > system_num:
        return "larger"
    elif player_num < system_num:
        return "smaller"
    else:
        return "equal"

def main():
    print("欢迎来玩猜数字的游戏")
    print("我将会选择一个100以内的自然数，你来猜是哪一个")
    
    while True:
        system_num = random.randint(1, 100)
        attempts = 0
        
        while True:
            answer = input("请你猜一个数字: ")
            
            try:
                player_num = int(answer)
            except ValueError:
                print("请输入一个有效的数字！")
                continue
            
            attempts += 1
            
            result = comparison(player_num, system_num)
            
            if result == "larger":
                print("这太大了")
            elif result == "smaller":
                print("这太小了")
            else:
                print(f"答对了！你一共猜了 {attempts} 次。")
                break
        
        play_again = input("你想再玩一次吗？(y/n): ")
        if play_again.lower() != 'y':
            print("谢谢游玩！再见！")
            break

if __name__ == "__main__":
    main()